package org.lanyu.springainovel.novel.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.lanyu.springainovel.novel.entity.BookAnalysisRecord;
import org.lanyu.springainovel.novel.entity.BookAnalysisResult;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

/**
 * 拆书记录服务接口
 */
public interface BookAnalysisRecordService {

    /**
     * 创建拆书记录并启动分�?     */
    BookAnalysisRecord createRecordAndStartAnalysis(BookAnalysisRecord record);

    /**
     * 获取当前用户的拆书记录列�?     */
    List<BookAnalysisRecord> getUserRecords();

    @Transactional
    BookAnalysisRecord createRecordAndStartAnalysis(String name, String sourceType, String sourcePath,
                                                    String sourceUrl, Long systemPromptId, Long modelId,
                                                    String userPrompt, Long userId);

    Page<BookAnalysisRecord> getUserRecords(Long userId, int page, int size);

    /**
     * 根据ID获取拆书记录
     */
    BookAnalysisRecord getRecordById(Long id);

    /**
     * 更新拆书记录
     */
    BookAnalysisRecord updateRecord(BookAnalysisRecord record);

    @Transactional
    BookAnalysisRecord updateRecord(Long id, String name, Long systemPromptId, Long modelId, String userPrompt);

    /**
     * 删除拆书记录
     */
    boolean deleteRecord(Long id);

    /**
     * 重新开始拆书分�?     */
    BookAnalysisRecord restartAnalysis(Long id);

    /**
     * 获取记录的状态和进度
     */
    BookAnalysisRecord getRecordStatus(Long id);

    /**
     * 获取拆书结果
     */
    List<BookAnalysisResult> getRecordResults(Long id);

    /**
     * 保存上传的文件并返回文件路径
     */
    String saveUploadedFile(org.springframework.web.multipart.MultipartFile file);
    
    /**
     * 获取正在运行的任务列�?     */
    java.util.Set<Long> getRunningTaskIds();
    
    /**
     * 异步执行拆书分析
     */
    CompletableFuture<Void> executeAnalysisAsync(BookAnalysisRecord record);
    
    /**
     * 异步处理文件上传并启动分�?     */
    CompletableFuture<Void> processFileAndStartAnalysis(BookAnalysisRecord record, MultipartFile file);
}
